package com.framework.base.controller;

import com.alibaba.dubbo.config.ApplicationConfig;
import com.alibaba.dubbo.config.ProtocolConfig;
import com.alibaba.dubbo.rpc.Protocol;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactoryUtils;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author chaolong.jin
 * @description
 * @date 2019/09/04 20:37
 */
@RestController
public class HealCheckController implements ApplicationContextAware {
    private ApplicationContext applicationContext;

    @GetMapping(value = "healthcheck")
    public String healthcheck() {
        return "ok";
    }


    @GetMapping(value = "shutDown")
    public String shutDown() {
//        Map<String, ProtocolConfig> applicationConfigMap = applicationContext == null ? null : BeanFactoryUtils.beansOfTypeIncludingAncestors(applicationContext, ProtocolConfig.class, false, false);
//        for (Map.Entry<String, ProtocolConfig> entry : applicationConfigMap.entrySet()) {
//            ProtocolConfig applicationConfig = entry.getValue();
//            applicationConfig.destory();
//        }
        ProtocolConfig.destroyAll();
        return "dubbo ShutDown";
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }
}
